package com.cndym.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * User: 邓玉明
 * Date: 2010-8-2
 * Time: 22:54:21
 */
public class LocalUtils {
    
    @SuppressWarnings("unchecked")
    public static Map<String,String> extractParameter(HttpServletRequest request){
        Enumeration<String> keys= request.getParameterNames();
		Map<String,String> values=new HashMap<String, String>();
		while(keys.hasMoreElements()){
			String key=keys.nextElement();
			String value= Utils.formatStr(request.getParameter(key),"");
            values.put(key, value);
		}
		return values;
	}    
    
    @SuppressWarnings("unchecked")
    public static Map<String,String> extractParameter(HttpServletRequest request, String encode){
        Enumeration<String> keys= request.getParameterNames();
        Map<String,String> values=new HashMap<String, String>();
        while(keys.hasMoreElements()){
            String key=keys.nextElement();
            String value = null;
            try {
                value = URLDecoder.decode(request.getParameter(key), encode);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            System.out.println(key +",Youmi," + value);
            values.put(key, Utils.formatStr(value, ""));
        }
        return values;
    }
    
    
    @SuppressWarnings("unchecked")
    public static Map<String,String> extractParameter(HttpServletRequest request, String encode, String inputCode){
        Enumeration<String> keys= request.getParameterNames();
        Map<String,String> values=new HashMap<String, String>();
        while(keys.hasMoreElements()){
            String key=keys.nextElement();
            String value = null;
            try {
                value = URLDecoder.decode(new String(request.getParameter(key).getBytes(inputCode)), encode);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            System.out.println(key +",Youmi," + value);
            values.put(key, Utils.formatStr(value, ""));
        }
        return values;
    }
    public static void main(String[] args) {
        String old = "ad=得脉adid=1437app=895131cf21915458chn=0device=3cd0f80d2e91order=YM130905smvH2wXi7cpoints=1price=1.61sig=e7e8dd76time=1378365111user=201211061006215862524c1c8f9f64ca0a15";
        String str = Md5.Md5(old);
        System.out.println(old);
        System.out.println(str);
    }
}
